﻿package  
{
	import Util.*;
	
	/**
	 * ...
	 * @author ...
	 */
	public class Sector 
	{
		private var _altitude:Number;
		private var _temperature:int;
		private var _humidity:int;
		private var _biome:int;
		private var _distanceToWater:int;
		
		public function Sector(world:World, x:int, y:int, biome:int) 
		{
			_altitude = new int(0);
			_temperature = new int(0);
			_humidity = new int(0);
			_distanceToWater = new int(0);
			
			if (_biome != Biome.MOUNTAINS + 1) {
				_biome = biome;
			}
			//biome = generateBiome(world, x, y);
		}
		
		public function get biome():int {
			return _biome;
		}
		
		public function set biome(value:int):void {
			_biome = value;
		}
		
		public function set altitude(value:Number):void {
			_altitude = value;
		}
		
		public function get distanceToWater():int {
			return _distanceToWater;
		}
		
		public function set distanceToWater(value:int):void {
			_distanceToWater = value;
		}
	
		private function generateHumidity(world:World, y:int):Number {
			var hum:Number;
			var altReduction:Number = 0.3;
			
			if ((y < world.getHeight() / 8) || (y > world.getHeight() - (world.getHeight() / 8)))
			{
				// For the arctic/antarctic climates, generate a random 
				// number between 0.0 to 0.6.
				hum = Utility.randomNumber(0, 0.6);
				
			}
			else if ((y < world.getHeight() / 4) || (y > world.getHeight() - (world.getHeight() / 4)))
			{
				// For the temperate climates, generate a random number 
				// between 0.1 and 0.7.
				hum = Utility.randomNumber(0.1, 0.7);
			}
			else if ((y < world.getHeight() / 2) || (y > world.getHeight() / 2))
			{
				// For the equatorial region, generate a random number 
				// between 0.0 and 1.0
				hum = Utility.randomNumber(0, 1.0);
			}
			
			if (_altitude > 1)
			{
				hum -= altReduction;
			}
			
			return hum;

		}
		
		/* Generate temperatures for the places in the three regions of Namatjira: 
			Arctic, Temperate, and Equatorial.
			
			Altitude lowers the temperature in a space by 7 to 12 C.
		*/
		private function generateTemperature(world:World, y:int):int {
			var temp:int;

			if ((y < world.getHeight() / 8) || (y > world.getHeight() - (world.getHeight() / 8)))
			{
				// For the arctic/antarctic climates, generate a random 
				// number between -75 and 0 C.
				temp = -Math.floor(Utility.randomNumber(0, 76));
				
			}
			else if ((y < world.getHeight() * (3/8)) || (y > world.getHeight() - (world.getHeight() * (3/8))))
			{
				// For the temperate climates, generate a random number 
				// between -5 and 30 C.
				temp = Math.floor(Utility.randomNumber(-5, 30));
			}
			else if ((y < world.getHeight() / 2) || (y > world.getHeight() / 2))
			{
				// For the equatorial region, generate a random number 
				// between 27 and 50 C.
				temp = Math.floor(Utility.randomNumber(27, 50));
			}
			
			if (_altitude > 1)
			{
				temp = temp - (Math.floor(Utility.randomNumber(7, 12)));
			}
			
			return temp;
		}
		
	}
	
}